//
//  HLMainViewController.swift
//  HLWeiBo
//
//  Created by jack on 15/12/5.
//  Copyright © 2015年 jack. All rights reserved.
//

import UIKit

class HLMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let tabBar = HLTabBar()
        
        tabBar.composeBtnClorsure = { [weak self] in
            print("点击事件")
            print(self?.view)
        }
        //使用KVC赋值
        setValue(tabBar, forKeyPath: "tabBar")
        
        addChildViewController(HLHomeTableViewController(), imageName: "tabbar_home", title: "首页")
        addChildViewController(HLMessageTableViewController(), imageName: "tabbar_message_center", title: "消息")
        addChildViewController(HLDiscoverTableViewController(), imageName: "tabbar_discover", title: "发现")
        addChildViewController(HLProfileTableViewController(), imageName: "tabbar_profile", title: "我")
        
    }

    func addChildViewController(childController: UIViewController, imageName: String, title: String ) {
        
        let vc = childController
        
        vc.title = title
        //方法一
//        UITabBar.appearance().tintColor = UIColor.orangeColor()
        //设置图片的内边距
//        vc.tabBarItem.imageInsets = UIEdgeInsets(top: 10, left: 0, bottom: 0, right: 0)
        vc.tabBarItem.image = UIImage(named: imageName)
        //方法二
        vc.tabBarItem.selectedImage = UIImage(named: "\(imageName)_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        vc.tabBarItem.setTitleTextAttributes([NSFontAttributeName: UIFont.systemFontOfSize(14)], forState: UIControlState.Normal)
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orangeColor()], forState: UIControlState.Selected)
        addChildViewController(HLNavigationController(rootViewController: vc))
    }
}
